import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class Frame1 extends Frame {
	public Frame1 () {
		super();
		try {
			jbInit();
		}
		catch (Exception e) {
			e.printStackTrace();
		}
	}
	public void jbInit() throws Exception {
		final JFrame f = new JFrame();
		Container container = f.getContentPane();
		container.setLayout(null);
		((JPanel)container).setBorder(BorderFactory.createTitledBorder("Kautotu"));
		final JLabel izena = new JLabel("Izena");
		izena.setBounds(20, 50, 60, 25);
		f.add(izena);
		JLabel pasahitza = new JLabel("Pasahitza");
		pasahitza.setBounds(20, 90, 60, 25);
		f.add(pasahitza);
		final TextField iTextua = new TextField();
		iTextua.setBounds(90, 50, 150, 25);
		f.add(iTextua);
		final TextField pTextua = new TextField();
		pTextua.setBounds(90, 90, 150, 25);
		pTextua.setEchoChar('*');
		f.add(pTextua);
		JButton kautotu = new JButton("Kautotu");
		kautotu.setBounds(20, 130, 100, 25);
		f.add(kautotu);
		JButton erregistratu = new JButton("Erregistratu");
		erregistratu.setBounds(130, 130, 110, 25);
		f.add(erregistratu);
		JButton produktuak = new JButton("Produktuak ikusi");
		produktuak.setBounds(20, 190, 140, 25);
		f.add(produktuak);
		f.setSize(300,300);
		f.setTitle("Euskaltoy");
		f.setVisible(true);
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		kautotu.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(ActionEvent e) {
				AplikazioDatuBase datubase = AplikazioDatuBase.instance();
				erabil erab = new erabil(iTextua.getText(), pTextua.getText());
				if (datubase.egiaztatu_erab(erab)) {
					kautotu_actionPerformed(e, iTextua.getText(), pTextua.getText());
					f.setVisible(false);
				}
				else {
					errorea_actionPerformed(e, iTextua.getText(), pTextua.getText());
					f.setVisible(false);
				}
			}
		});
		erregistratu.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(ActionEvent e) {
				erregistratu_actionPerformed(e);
				f.setVisible(false);
			}
		});
		produktuak.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(ActionEvent e) {
				produktuak_actionPerformed(e);
				f.setVisible(false);
			}
		});
	}
	void kautotu_actionPerformed(ActionEvent e, String izena, String pas) {
		new ErabiltzaileAukerak(this, true, izena, pas);
	}
	void errorea_actionPerformed(ActionEvent e, String izena, String pas) {
		new Errorea(this, true, 1, izena, pas);
	}
	void erregistratu_actionPerformed(ActionEvent e) {
		new Erregistratu(this, true);
	}
	void produktuak_actionPerformed(ActionEvent e) {
		new Produktuak(this, true);
	}
}
